{{#if entityLogic.isEnableBackend}}
package logic.{{entityLogic.entity.codeName}}

import cn.ibizlab.util.domain.EntityBase
import cn.ibizlab.util.helper.RuleUtils
import cn.ibizlab.util.security.AuthenticationUser
import cn.ibizlab.util.security.SpringContextHolder
{{#each entityLogic.opt.pSDELogicParams as |param|}}
    {{#param.paramPSDataEntity}}
import {{packageName}}.core.{{lowerCase param.paramPSDataEntity.pSSystemModule.codeName}}.domain.{{pascalCase param.paramPSDataEntity.codeName}}
{{#param.paramPSDataEntity.storageMode}}
import {{packageName}}.core.{{lowerCase param.paramPSDataEntity.pSSystemModule.codeName}}.service.{{pascalCase param.paramPSDataEntity.codeName}}Service
{{/param.paramPSDataEntity.storageMode}}
    {{/param.paramPSDataEntity}}
{{/each}}
import com.alibaba.fastjson.JSONObject
import org.springframework.util.ObjectUtils

/**
 *  {{entityLogic.name}}
 */
class {{entityLogic.codeName}} {

    //当前用户
    def curuser = AuthenticationUser.getAuthenticationUser()
{{#each entityLogic.opt.pSDELogicParams as |param|}}
    {{#param.paramPSDataEntity}}
    //{{param.name}}
    def _{{lowerCase param.codeName}}{{#unless param.isDefault}} = new {{pascalCase param.paramPSDataEntity.codeName}}(){{/unless}}
    {{else}}
    def _{{lowerCase param.codeName}} = new EntityBase()
    {{/param.paramPSDataEntity}}
{{/each}}
    //返回参数
    def _return

    def execute(arg) {
        println 'running....'
{{#each entityLogic.opt.pSDELogicParams as |param|}}
    {{#param.paramPSDataEntity}}
        {{#param.isDefault}}_{{lowerCase param.codeName}} = arg{{/param.isDefault}}
    {{/param.paramPSDataEntity}}
{{/each}}
        _return = arg
        {{camelCase entityLogic.opt.startPSDELogicNode.codeName}}()
        println 'running end....'
        return _return
    }

{{#each entityLogic.logicNodeModels as |logicNodeModel|}}
    //{{logicNodeModel.name}}
    def {{camelCase logicNodeModel.codeName}}() {
    {{#if (eq logicNodeModel.logicNodeType "BEGIN")}}
    {{> @macro/logic/groovy/Begin.hbs logicNodeModel=logicNodeModel}}
    {{else if (eq logicNodeModel.logicNodeType "PREPAREPARAM")}}
    {{> @macro/logic/groovy/PrepareParam.hbs logicNodeModel=logicNodeModel}}
    {{else if (eq logicNodeModel.logicNodeType "RESETPARAM")}}
    {{> @macro/logic/groovy/ResetParam.hbs logicNodeModel=logicNodeModel}}
    {{else if (eq logicNodeModel.logicNodeType "COPYPARAM")}}
    {{> @macro/logic/groovy/CopyParam.hbs logicNodeModel=logicNodeModel}}
    {{else if (eq logicNodeModel.logicNodeType "BINDPARAM")}}
    {{> @macro/logic/groovy/BindParam.hbs logicNodeModel=logicNodeModel}}
    {{else if (eq logicNodeModel.logicNodeType "APPENDPARAM")}}
    {{> @macro/logic/groovy/AppendParam.hbs logicNodeModel=logicNodeModel}}
    {{else if (eq logicNodeModel.logicNodeType "SORTPARAM")}}
    {{> @macro/logic/groovy/SortParam.hbs logicNodeModel=logicNodeModel}}
    {{else if (eq logicNodeModel.logicNodeType "RENEWPARAM")}}
    {{> @macro/logic/groovy/RenewParam.hbs logicNodeModel=logicNodeModel}}
    {{else if (eq logicNodeModel.logicNodeType "DEBUGPARAM")}}
    {{> @macro/logic/groovy/DebugParam.hbs logicNodeModel=logicNodeModel}}
    {{else if (eq logicNodeModel.logicNodeType "DEACTION")}}
    {{> @macro/logic/groovy/DEAction.hbs logicNodeModel=logicNodeModel}}
    {{else if (eq logicNodeModel.logicNodeType "DEDATAQUERY")}}
    {{> @macro/logic/groovy/DEDataQuery.hbs logicNodeModel=logicNodeModel}}
    {{else if (eq logicNodeModel.logicNodeType "DEDATASET")}}
    {{> @macro/logic/groovy/DEDataSet.hbs logicNodeModel=logicNodeModel}}
    {{else if (eq logicNodeModel.logicNodeType "DENOTIFY")}}
    {{> @macro/logic/groovy/DENotify.hbs logicNodeModel=logicNodeModel}}
    {{else if (eq logicNodeModel.logicNodeType "STARTWF")}}
    {{> @macro/logic/groovy/StartWF.hbs logicNodeModel=logicNodeModel}}
    {{else if (eq logicNodeModel.logicNodeType "CANCELWF")}}
    {{> @macro/logic/groovy/CancelWF.hbs logicNodeModel=logicNodeModel}}
    {{else if (eq logicNodeModel.logicNodeType "DELOGIC")}}
    {{> @macro/logic/groovy/DELogic.hbs logicNodeModel=logicNodeModel}}
    {{else if (eq logicNodeModel.logicNodeType "SYSLOGIC")}}
    {{> @macro/logic/groovy/SysLogic.hbs logicNodeModel=logicNodeModel}}
    {{else if (eq logicNodeModel.logicNodeType "SUBSYSSAMETHOD")}}
    {{> @macro/logic/groovy/SubSysMethod.hbs logicNodeModel=logicNodeModel}}
    {{else if (eq logicNodeModel.logicNodeType "RAWWEBCALL")}}
    {{> @macro/logic/groovy/RawWebCall.hbs logicNodeModel=logicNodeModel}}
    {{else if (eq logicNodeModel.logicNodeType "RAWSQLCALL")}}
    {{> @macro/logic/groovy/RawSQLCall.hbs logicNodeModel=logicNodeModel}}
    {{else if (eq logicNodeModel.logicNodeType "RAWSQLANDLOOPCALL")}}
    {{> @macro/logic/groovy/RawSQLAndLoopCall.hbs logicNodeModel=logicNodeModel}}
    {{else if (eq logicNodeModel.logicNodeType "SYSDBTABLEACTION")}}
    {{> @macro/logic/groovy/SysDBTableAction.hbs logicNodeModel=logicNodeModel}}
    {{else if (eq logicNodeModel.logicNodeType "RAWSFCODE")}}
    {{> @macro/logic/groovy/RawSFCode.hbs logicNodeModel=logicNodeModel}}
    {{else if (eq logicNodeModel.logicNodeType "SFPLUGIN")}}
    {{> @macro/logic/groovy/SFPlugin.hbs logicNodeModel=logicNodeModel}}
    {{else if (eq logicNodeModel.logicNodeType "THROWEXCEPTION")}}
    {{> @macro/logic/groovy/ThrowException.hbs logicNodeModel=logicNodeModel}}
    {{else if (eq logicNodeModel.logicNodeType "END")}}
    {{> @macro/logic/groovy/End.hbs logicNodeModel=logicNodeModel}}
    {{else}}
    //未支持的处理节点
    {{/if}}

        {{#if logicNodeModel.parallelOutput}}
            {{#each logicNodeModel.logicLinkModels as |logicLinkModel|}}
                {{#unless logicLinkModel.opt.catchLink}}
        //{{logicLinkModel.name}}
        if({{#if logicLinkModel.hasCondtion}}{{logicLinkModel.condition}}{{else}}true{{/if}}) {
            {{camelCase logicLinkModel.pSDELogicLink.dstPSDELogicNode.codeName}}()
        }
                {{/unless}}
            {{/each}}
        {{else}}
            {{#if onlyOneLink}}
        if({{#if onlyOneLink.hasCondtion}}{{onlyOneLink.condition}}{{else}}true{{/if}}) {
            {{camelCase onlyOneLink.pSDELogicLink.dstPSDELogicNode.codeName}}()
        }
            {{else}}
            {{#each logicNodeModel.logicLinkModels as |logicLinkModel|}}
                {{#unless logicLinkModel.opt.catchLink}}
                    {{#unless logicLinkModel.opt.defaultLink}}
        //{{logicLinkModel.name}}
        {{#unless logicLinkModel.nodeFirstLink}}else {{/unless}}if({{#if logicLinkModel.hasCondtion}}{{logicLinkModel.condition}}{{else}}true{{/if}}) {
            {{camelCase logicLinkModel.pSDELogicLink.dstPSDELogicNode.codeName}}()
        }
                    {{/unless}}
                {{/unless}}
            {{/each}}
            {{#if logicNodeModel.defaultLinkModel}}
        else {
            {{camelCase logicNodeModel.defaultLinkModel.pSDELogicLink.dstPSDELogicNode.codeName}}()
        }
            {{/if}}
            {{/if}}
        {{/if}}
    }

{{/each}}
}
{{/if}}